

(async()=>{
    //创建应用对象
    const express = require('express')
    const bookRouter = require('./routers/bookRouter')
    const db = require('./db');
    await db()
    const app = express()

    app.use(function(req, res, next){
        res.setHeader('Access-Control-Allow-Origin', '*');  // 允许跨域请求
        res.setHeader('Access-Control-Allow-Headers', "*"); // 该响应头 允许客户端可以设置『自定义』请求头  
        res.setHeader('Access-Control-Allow-Methods', "*"); // 允许各种请求方式进行跨域请求 get post delete put patch
        next();
      });
    // 使用中间件:静态资源,bodyParser,路由器
    app.use(express.static('public'))
    app.use(express.urlencoded({extended:false}))
    app.use(express.json())
    app.use('/book',bookRouter)


    app.set('view engine', 'ejs')
    app.set('views','./views')

    app.listen('3007',()=>{
        console.log('服务器启动成功:http://localhost:3007');
    })


})()

    
